package edu.xhu.behavior.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.xhu.behavior.mapper.BiliUserDanmuMapper;
import edu.xhu.behavior.service.BiliUserDanmuService;
import edu.xhu.model.behavior.enums.DanMuState;
import edu.xhu.model.behavior.pojos.BiliUserDanmu;
import edu.xhu.model.common.dtos.ResponseResult;
import edu.xhu.model.common.enums.AppHttpCodeEnum;
import edu.xhu.model.common.enums.IsFlagEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;



@Service
@RequiredArgsConstructor
@Slf4j
public class BiliUserDanmuServiceImpl extends ServiceImpl<BiliUserDanmuMapper, BiliUserDanmu> implements BiliUserDanmuService {

    private final BiliUserDanmuMapper biliUserDanmuMapper;

    /**
     * 根据视频id获取弹幕列表
     */
    @Override
    public ResponseResult<?> getDanmuList(Long videoId) {
        if (videoId == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return ResponseResult.okResult(biliUserDanmuMapper.selectList(Wrappers.<BiliUserDanmu>lambdaQuery()
                .eq(BiliUserDanmu::getVideoId, videoId)
                .eq(BiliUserDanmu::getState, DanMuState.PASS.getCode())
                .eq(BiliUserDanmu::getIsShield, IsFlagEnum.NO.getCode())));
    }

    /**
     * 根据弹幕id删除弹幕
     */
    @Override
    public ResponseResult<?> deleteDanmu(Long dmId) {
        if (dmId == null) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        int i = biliUserDanmuMapper.deleteById(dmId);
        if (i < 1) {
            return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
